package com.course.controller.student;

import com.course.entity.Result;
import com.course.server.StuService;
import com.course.vo.ChooseCourse;
import com.course.vo.StudentCredit;
import com.course.vo.StudentsCourse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("StudentController")
@CrossOrigin
@RequestMapping("/student")
@Tag(name = "学生端-学生接口",description = "管理")
public class StudentController {
    @Autowired
    private StuService stuService;
    /**
     * 获取学生学分信息
     * @return
     */
    @GetMapping("/stuCredit/{sno}")
    public Result studentCredit(Integer sno){
        log.info("获取学生学分信息");
        List<StudentCredit> studentCredits=stuService.studentCredit(sno);
        return Result.sucess(studentCredits);
    }
    /**
     * 进行选课
     * @param chooseCourse
     * @return
     */
    @PutMapping("/choose")
    public Result ChooseCourse(@RequestBody ChooseCourse chooseCourse){
        log.info("学生进行选课:{}",chooseCourse);
        stuService.ChooseCourse(chooseCourse);
        return Result.sucess();
    }

    /**
     * 查询已经选修了的课程的成绩
     * @param sno
     * @return
     */
    @GetMapping("/course/{sno}")
    public Result GetCourse(@PathVariable Integer sno){
        log.info("查询学生选修的课程:{}",sno);
        List<StudentsCourse> GetCourse=stuService.GetCourse(sno);
        return Result.sucess(GetCourse);
    }

    /**
     * 根据课程号和学号退选课程
     * @param sno
     * @param cno
     * @return
     */
    @DeleteMapping("/{sno}/{cno}")
    public Result DeleteCourse(@PathVariable Integer sno
                                ,@PathVariable String cno){
        log.info("根据课程号和学号退选课程:{}",sno,cno);
        stuService.deleteByCno(sno,cno);
        return Result.sucess();
    }
}
